public class Solution396 {
    public int maxRotateFunction(int[] nums) {
        int cur=0;
        int sum=0;
        for (int i=0;i<nums.length;i++){
            cur+=i*nums[i];
            sum+=nums[i];
        }
        int max=cur;
        for (int i=0;i<nums.length;i++){
            cur=cur-sum+nums.length*nums[i];
            max=Math.max(max,cur);
        }
        return max;
    }

    public static void main(String[] args) {
        System.out.println(new Solution396().maxRotateFunction(new int[]{4,3,2,6}));
    }
}
